package com.member.provider.service.impl;

import com.member.api.pay.TestYFHInterfaceByPaySecretFree;
import com.member.dto.FreePay;
import com.member.dto.PayType;
import com.member.provider.mapper.PayMapper;
import com.member.provider.service.PayService;
import com.member.utils.Result;
import com.member.vo.FreeRefundReqVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @auther liujian
 * @date 2023/12/26 15:24
 */
@Service
public class PayServiceImpl implements PayService {

    @Autowired
    private PayMapper payMapper;

    /**
     * @Description TODO
     * @param payType
     * @retuen Result
     * @date 2023/12/29 14:55
     * @auther 银狐先生
     */
    @Override
    public Result addPay(PayType payType) {



        Integer integer=payMapper.addPay(payType);
        if (integer>0){
         return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }

    @Override
    public Result freePay(FreePay freePay) {

        try {
            TestYFHInterfaceByPaySecretFree.paySecretFree();
            HashMap<String, String> json = new HashMap<>();
            json.put("channelId","");
            json.put("timeStamp","");
            json.put("notifyUrl","");
            json.put("hospitalId","");
            json.put("orderId", "");
            json.put("txnAmt", "");
            json.put("termId","");
            json.put("reqReserved","");
            json.put("yhf_token","");
            json.put("orderDesc","");
            json.put("YhfToken", "");
            json.put("UserName", "");
            String s = TestYFHInterfaceByPaySecretFree.generateSignature(String.valueOf(json), "");
            if (s.equals("")){
                StringBuffer sortSb = new StringBuffer();
                ArrayList<Object> objects = new ArrayList<>();
            }


        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return null;
    }

    @Override
    public Result delFreePay(Long id) {
        return null;
    }

    @Override
    public Result refundPay(FreeRefundReqVo refundReqVo) {
        return null;
    }

    @Override
    public Result selectPay() {
        List<PayType> payTypes= payMapper.selectPay();
        return Result.success(payTypes);
    }

    @Override
    public Result getPaytypeById(Long payId) {
        List<PayType> payTypes = payMapper.getPaytypeById(payId);
        return Result.success(payTypes);
    }

//    @Override
//    public Result processPaymentNotification(PaymentNotification paymentNotification) {
//        // 根据银联推送的结果更新用户支付状态
//        // 可能需要根据paymentNotification中的信息查询用户信息，并更新数据库中的支付状态
//        return null;
//    }


}
